<?php

if(isset($_POST['dt_inicial']) or isset($_POST['dt_final']))
{
    include_once 'app.ado/DataBase.php';
    
    $s = new DataBase();
    $db = $s->getConn();
    
    include 'app.functions/formataData.php';
    
    $dt_inicial = isset($_POST['dt_inicial']) ? formataData($_POST['dt_inicial']) : '2000-01-01';
    $dt_final = isset($_POST['dt_final']) ? formataData($_POST['dt_final']) : date('Y-m-d');

    $sql = 'select * from emprestimos
where dt_inicial_emprestimo between ? and ?
order by dt_inicial_emprestimo;';
    $sth = $db->prepare($sql);

    $sth->execute(array($dt_inicial,$dt_final));

    $req = $sth->fetchAll(PDO::FETCH_CLASS, "Emp");

    $rel = new TRelEmprestimo($req);
    $rel->render();

    //header('location: index.php');
}
    
?>
